import Sequelize = require('sequelize')
const service = require('feathers-sequelize')

//约定:表名同该文件名
const lastSlashIndex = __filename.lastIndexOf("/")
const lastDotIndex = __filename.lastIndexOf(".")
const tableName = 'tb_' + 'supplier_product'

const fields = {
    id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
    },
    supplier_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
    },
    product_code: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    product_code_custom: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    name: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    cover_image: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    barcode: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    standard: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    cost: {
        type: Sequelize.DOUBLE,
        allowNull: false,
    },
    price: {
        type: Sequelize.DOUBLE,
        allowNull: false,
    },
    special_price: {
        type: Sequelize.DOUBLE,
        allowNull: false,
    },
    place: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    place_index: {
        type: Sequelize.INTEGER,
        allowNull: false,
    },
    stock: {
        type: Sequelize.INTEGER,
        allowNull: false,
    },
    letter: {
        type: Sequelize.STRING,
        allowNull: false,
    },
    keywords: {
        type: Sequelize.TEXT,
        allowNull: false,
    },
    has_discount: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
    },
    is_deleted: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
    },
    sort_index: {
        type: Sequelize.FLOAT,
        allowNull: false,
    },
    status: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
    },
    create_time: {
        type: Sequelize.BIGINT,
        allowNull: false,
    },
    update_time: {
        type: Sequelize.BIGINT,
        allowNull: false,
    },
}

const classMethods = {
    associate(models: any[]) {

    }
}

export = function (sequelize: Sequelize.Sequelize) {
    let options = {
        tableName,
        classMethods
    }
    let Model = sequelize.define(tableName, fields, options)
    return Model
}